clear all
tic
mcvar=zeros(5001,5000);
for ii=1:1
    disp(ii)
    randseed=randn(5000,5000);
    samplepaths=oupath(randseed,1,1,1,1);
    clear randseed
    dW=randn(5000,5000);
    mcvar=mcvar+mcforpart2(samplepaths,dW);
%     for jj=1:51
%         disp(jj)
%         mcvar(jj,:)=sum(sigmadW(1:(jj-1)*100+1,:),1);
%     end
%     for jj=2:51
%         disp(jj)
%         mcvar(jj)=mcvar(jj)+sqrt(0.5/5000)*sum(sum(samplepaths(100*(jj-2)+1:100*(jj-1)+1,:).*randseed(100*(jj-2)+1:100*(jj-1)+1,:),1));
%     end
end

mcvar2=sum(mcvar.^2,2)/5000;
toc

% a=1;b=1;m=1;yic=1;
time=(0:5000)*0.5/5000;
% exactvar=b^2/2/a*(1-exp(-2*a*time))'+(m+(yic-m)*exp(-a*time)).^2';
plot(time,mcvar2)
% hold on
% plot(time,exactvar,'r')